<template >
      <div style="margin: 20px">
        <zh-form ref="formRef" :md="24" :lg="24" :xl="24"  :model="consumerInfo" :rules="rules">
          <zh-form-input prop="funcTitle" label="申请接口名称"  v-model="consumerInfo.funcTitle"
                         disabled></zh-form-input>
          <zh-form-input prop="funcCode" v-show = "consumerInfo.consumerAuth != '1'" label="申请接口编码"  v-model="consumerInfo.funcCode"
                         disabled></zh-form-input>
          <zh-form-input prop="param1"  v-show = "consumerInfo.consumerAuth =='1'" label="接口调用编码"  v-model="consumerInfo.param1"
                         disabled></zh-form-input>
          <zh-form-input prop="param2" v-show = "consumerInfo.consumerAuth =='1'" label="接口调用路径"  v-model="consumerInfo.param2"
                         disabled></zh-form-input>
          <zh-form-select
              prop="appId"
              :lazy="true"
              label="所属应用"
              v-model="consumerInfo.appId"
              :fieldNames="{ label: 'appName', value: 'appId' }"
              funcCode="application0012"
              :disabled="props.displayFlag"
              searchField="appName"
              @change="appIdChange"
          ></zh-form-select>
          <zh-form-select
              prop="envId"
              label="应用环境"
              :options="state.envDict"
              placeholder="应用环境"
              :disabled="props.displayFlag"
              v-model="consumerInfo.envId"
          ></zh-form-select>
          <zh-form-input prop="devOrgName" label="所属开发公司"  v-model="consumerInfo.devOrgName"
                         disabled></zh-form-input>
          <zh-form-input prop="devName" label="开发人员姓名"  v-model="consumerInfo.devName"
                         disabled></zh-form-input>
          <zh-form-select
              :disabled="props.displayFlag"
              prop="status"
              label="有效状态"
              :options="state.dictData.status"
              v-model="consumerInfo.status"
          ></zh-form-select>
          <zh-form-input prop="visits" label="日访问上限" :disabled="props.displayFlag" v-model="consumerInfo.visits">
          </zh-form-input>
          <zh-form-input prop="frequency" label="调用频次" :disabled="props.displayFlag" v-model="consumerInfo.frequency">
          </zh-form-input>
          <zh-form-input
              :disabled="props.displayFlag"
              prop="remarks"
              :span="24"
              label="描述"
              type="textarea"
              v-model="consumerInfo.remarks"
          ></zh-form-input>
        </zh-form>
      </div>
</template>
<script lang="ts" setup name="consumerInfo">
import {FormInstance} from "element-plus";
const props = defineProps({
  scrollHeight: {
    type: String,
    default: ''
  },
  displayFlag: {
    type: Boolean,
    default:false
  },
});

const {isTagsview} = storeToRefs($store.theme);
//------------------定义子组件---------------------------
const formRef = ref<FormInstance>();
const consumerInfo = ref<any>({
  status:'1'
});

//------------------内部变量定义-------------------------
const state = reactive({
  dictData:[],
  envDict:[]
});
const rules = reactive({});

//------------------定义调用方法-------------------------

//------------------初始化------------------------------
const params = {
  dictFields: 'status',
};
$api.common.getBatchDict.post(params).then((res) => {
  state.dictData = res.result;
});


function setInitDate(info) {
  formRef.value?.resetFields();
  if (info) {
    if(!props.displayFlag){
      consumerInfo.value.funcId=info.funcId;
      consumerInfo.value.funcCode=info.funcCode;
      consumerInfo.value.funcTitle=info.funcTitle;
    }else{
      //根据id获取详细信息
      $api.common.send.post('APICONSUMER0002', {consumerId:info.consumerId}).then((res) => {
        consumerInfo.value = res.result;
      }).catch(() => {});
    }
  }
}
function appIdChange(e) {

  if (e) {
    $api.common.send.post('apiAppEnv0007',{appId: e}).then(res => {
      if (res.result) {
        state.envDict = res.result
      }
    }).catch(e => {

    });
  } else {
    state.envDict = [];
  }
}

function saveConsumerInfo(){
      $api.common.send.post('APICONSUMER0004', consumerInfo.value).then((res) => {
        $messageBox.success('提交成功', '提示');
      }).catch(() => {});
}
//------------设置给父组件调用的数据/方法(组件)-----------
defineExpose({setInitDate, form: formRef, consumerInfo,saveConsumerInfo});
</script>

